import%20marimo%0A%0A__generated_with%20%3D%20%220.17.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20auto_download%3D%5B%22html%22%2C%20%22ipynb%22%5D)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20pytz%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20india_timezone%20%3D%20pytz.timezone(%22Asia%2FKolkata%22)%0A%20%20%20%20now%20%3D%20datetime.datetime.now(india_timezone)%0A%0A%20%20%20%20curr%20%3D%20now.strftime(%22%25Y-%25m-%25d%2C%20%25I%3A%25M%3A%25S%20%25p%20%25Z%22)%0A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20rf%22%22%22%0A%20%20%20%20%23%20Week%20-%209%0A%0A%20%20%20%20**Submission%20Date%3A**%20%602025-11-30%2C%2023%3A59%20IST%60%0A%0A%20%20%20%20**Last%20Updated%3A**%20%60%7Bcurr%7D%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20from%20sklearn.preprocessing%20import%20LabelEncoder%2C%20StandardScaler%0A%20%20%20%20from%20sklearn.cluster%20import%20KMeans%2C%20AgglomerativeClustering%0A%20%20%20%20from%20sklearn.metrics%20import%20accuracy_score%0A%20%20%20%20from%20scipy.stats%20import%20mode%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20AgglomerativeClustering%2C%0A%20%20%20%20%20%20%20%20KMeans%2C%0A%20%20%20%20%20%20%20%20LabelEncoder%2C%0A%20%20%20%20%20%20%20%20StandardScaler%2C%0A%20%20%20%20%20%20%20%20accuracy_score%2C%0A%20%20%20%20%20%20%20%20pd%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Data%20Set%20Information%3A%0A%0A%20%20%20%20Live%20selling%20is%20becoming%20increasingly%20popular%20in%20Asian%20countries.%20Small%20vendors%20can%20now%20reach%20a%20wider%20audience%20and%20connect%20with%20many%20customers.%20Analyze%20The%20variability%20of%20consumer%20engagement%20on%20Facebook%20Live%20data%20which%20can%20help%20sellers%20to%20build%20selling%20approach%20and%20activities%20for%20the%20company.%0A%20%20%20%20%22%22%22).callout()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Assignment%20Information%0A%0A%20%20%20%20**(Consider%20the%20statement%20for%20Q1-%20Q8)%20Load%20the%20dataset%20using%20following%20link**%0A%0A%20%20%20%20Url%20%3D%20%22https%3A%2F%2Farchive.ics.uci.edu%2Fml%2Fmachine-learning-databases%2F00488%2FLive_20210128.csv%22%0A%0A%20%20%20%20Check%20if%20any%20feature%20contains%20**Null**%20values.%0A%0A%20%20%20%20Drop%20all%20the%20features%20which%20have%20**Null**%20values.%0A%0A%20%20%20%20Save%20%60'status_type'%60%20as%20target%20variable.%0A%0A%20%20%20%20Drop%20the%20feature%20%60%22status_id%22%60%2C%20%60%22status_type%22%60%20and%20%60%22status_published%22%60%20from%20training%20set.%0A%0A%20%20%20%20Use%20LabelEncoder%20to%20transform%20the%20target%20variable.%0A%0A%20%20%20%20Use%20standard%20scaler%20to%20scale%20the%20features.%0A%0A%20%20%20%20**For%20Q4%2CQ5**%20Train%20the%20model%20using%20Kmeans%20clustering%20(Take%20Random%20state%3D10)%0A%0A%20%20%20%20**For%20Q6%2CQ7%2CQ8**%20Train%20the%20model%20using%20Agglomerative%20Clustering%20by%20setting%20the%20parameter%20as%20following%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pd)%3A%0A%20%20%20%20df%20%3D%20pd.read_csv(%0A%20%20%20%20%20%20%20%20%22https%3A%2F%2Farchive.ics.uci.edu%2Fml%2Fmachine-learning-databases%2F00488%2FLive_20210128.csv%22%0A%20%20%20%20)%0A%20%20%20%20return%20(df%2C)%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20X%20%3D%20df.drop(%22status_type%22%2C%20axis%3D1)%0A%20%20%20%20y%20%3D%20df%5B%22status_type%22%5D%0A%20%20%20%20return%20X%2C%20y%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%201%0A%0A%20%20%20%20What%20is%20the%20shape%20of%20the%20data%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.shape%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%202%0A%0A%20%20%20%20How%20many%20feature%20contain%20Null%20values%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20(X.isnull().sum()%20%3E%200).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%203%0A%0A%20%20%20%20Column%20'%60status_type%60'%20has%20_%20_%20_%20_%20(number)%20unique%20values.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df%5B%22status_type%22%5D.unique().size%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%204%20-%208%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Preprocessing%20Steps%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20for%20_k%2C%20_v%20in%20X.isnull().sum().items()%3A%0A%20%20%20%20%20%20%20%20if%20_v%20%3E%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20X.drop(_k%2C%20axis%3D1%2C%20inplace%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20X.drop(%5B%22status_id%22%2C%20%22status_published%22%5D%2C%20axis%3D1%2C%20inplace%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(LabelEncoder%2C%20X%2C%20y)%3A%0A%20%20%20%20for%20_col%20in%20X.select_dtypes(include%3D%22object%22).columns%3A%0A%20%20%20%20%20%20%20%20le%20%3D%20LabelEncoder()%0A%20%20%20%20%20%20%20%20X%5B_col%5D%20%3D%20le.fit_transform(X%5B_col%5D)%0A%0A%20%20%20%20y_true%20%3D%20LabelEncoder().fit_transform(y)%0A%20%20%20%20return%20(y_true%2C)%0A%0A%0A%40app.cell%0Adef%20_(StandardScaler%2C%20X)%3A%0A%20%20%20%20ss%20%3D%20StandardScaler().set_output(transform%3D%22pandas%22)%0A%20%20%20%20X_trans%20%3D%20ss.fit_transform(X)%0A%20%20%20%20return%20(X_trans%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%204%20-%205%0A%0A%20%20%20%20For%20**Q4**%2C%20**Q5**%20Train%20the%20model%20using%20Kmeans%20clustering%20(Take%20**Random%20state%3D10**)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%204%0A%0A%20%20%20%20Enter%20the%20inertia%20score%20at%20**k%3D2**%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(KMeans%2C%20X_trans)%3A%0A%20%20%20%20_kmeans%20%3D%20KMeans(2%2C%20random_state%3D10%2C%20n_init%3D10)%0A%20%20%20%20_kmeans.fit(X_trans)%0A%0A%20%20%20%20_kmeans.inertia_%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%205%0A%0A%20%20%20%20How%20many%20labels%20were%20predicted%20accurately%20at%20k%3D4%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(KMeans%2C%20X_trans%2C%20y_true)%3A%0A%20%20%20%20_kmeans%20%3D%20KMeans(4%2C%20random_state%3D10%2C%20n_init%3D10)%0A%20%20%20%20_labels%20%3D%20_kmeans.fit_predict(X_trans)%0A%0A%20%20%20%20(_labels%20%3D%3D%20y_true).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%206%20-%208%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(AgglomerativeClustering%2C%20X_trans%2C%20y)%3A%0A%20%20%20%20aggo%20%3D%20AgglomerativeClustering(%0A%20%20%20%20%20%20%20%20n_clusters%3D4%2C%20metric%3D%22euclidean%22%2C%20linkage%3D%22ward%22%0A%20%20%20%20)%0A%20%20%20%20aggo.fit(X_trans%2C%20y)%0A%20%20%20%20return%20(aggo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%206%0A%0A%20%20%20%20What%20is%20the%20label%20predicted%20for%20first%20row%20of%20samples%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(aggo)%3A%0A%20%20%20%20aggo.labels_%5B0%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%207%0A%0A%20%20%20%20Enter%20the%20number%20of%20leaves%20in%20the%20hierarchical%20tree.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(aggo)%3A%0A%20%20%20%20aggo.n_leaves_%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%208%0A%0A%20%20%20%20What%20is%20the%20accuracy%20of%20the%20model(in%20Percentage)%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(accuracy_score%2C%20aggo%2C%20y_true)%3A%0A%20%20%20%20accuracy_score(y_true%2C%20aggo.labels_)%20*%20100%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
d0fb018112fdbeb5a020fb05d6d77cc1d22799d0224f63186a8042f1274b3b38